Throttled progress/cancel callback for load_obj_buf - #79
Open
virtualritz wants to merge 1 commit into
Open
Conversation
LoadOptions gains progress_callback: Option<LoadProgressCallback> (Arc<dyn Fn(&LoadProgress) -> ControlFlow<()> + Send + Sync>, an options field rather than a second _with_progress function), invoked every 1000 lines during load_obj_buf's parse loop. Returning ControlFlow::Break stops the load and returns the new LoadError::Cancelled. No behavior change when progress_callback is None (the default): verified by a test comparing output with and without a no-op callback. load_obj_buf_async is untouched.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LoadOptionsgainsprogress_callback: Option<LoadProgressCallback>(Arc<dyn Fn(&LoadProgress) -> ControlFlow<()> + Send + Sync>), an options field rather than a second_with_progressfunction, so a caller can observe throttled progress and cooperatively cancel a load of a large OBJ buffer.load_obj_buf's parse loop. ReturningControlFlow::Breakstops the load and returns the newLoadError::Cancelled.progress_callbackisNone(the default): verified by a test comparing output with and without a no-op callback.load_obj_buf_async(thefutures/tokiovariants) is intentionally untouched — that's a materially different code path deserving its own design pass.LoadOptionsloses itsCopyderive (Arcisn'tCopy); every existing call site in this crate already passes&LoadOptions, so nothing else needed to change.Motivated by a real use case: an interactive mesh-editing tool importing large OBJ files needed a way to show progress and let a user cancel a slow import without the caller being able to observe anything until the whole call returned.
Test plan
cargo test --all-features: 21 lib tests + 5 doctests pass, including 3 new tests (test_progress_callback_noop_matches_no_callback,test_progress_callback_cancels_load,test_progress_callback_is_throttled)cargo fmt --all -- --check: cleancargo clippy --all-targets --all-features -- -D warnings: clean (exit 0)